var view = new Vue({
    el: '#view',
    data: {
        imgurl: imgurl,
        ffList: [],
        ffInfo: {},
        listData: {
            phone: '',
            password: '',
            send_code: '',
            name: '',
            city: '',
            offten_city: '',
            age: '',
            occupation: '',
            dy_program: '',
            dy_conditions: '',
            wxcount: '',
            qq: '',
            stature: '',
            weight: '',
            self_slogan: '',
            sex: getCookie('sex'),
            head: '',
             wechat: getCookie('wechat')
        },
    },
    methods: {
        _url: function (param, url) {
            _url(param, url);
        },
        // 图片自适应
        imgCss: function (url, event) {
            var e = event.currentTarget;
            imgCss(url, function (w, h) {
                if (w < h) {
                    $(e).parent().addClass('img-w').removeClass('img-h');
                }
            })
        },
    }
})
// view.listData.userid = getCookie('userid');
// view.listData.phone = pageParam['phone'];
// view.listData.password = pageParam['password'];
view.listData.send_code = pageParam['send_code'];
// 提交个人资料
function submit() {
    if (!view.listData.head) {
        _msg('请上传头像');
        return;
    }
    if (!view.listData.name) {
        _msg('昵称还没未填写');
        return;
    }
    if (!view.listData.city) {
        _msg('请选择当前城市');
        return;
    }
    if (!view.listData.offten_city) {
        _msg('请选择常驻城市');
        return;
    }
    if (!view.listData.age) {
        _msg('请选择年龄');
        return;
    }
    if (!view.listData.occupation) {
        _msg('请选择职业');
        return;
    }
    if (!view.listData.dy_program) {
        _msg('请选择交友节目');
        return;
    }
    if (!view.listData.dy_conditions) {
        _msg('请选择约会条件');
        return;
    }
    if (!view.listData.wxcount && !view.listData.qq) {
        _msg('微信和qq至少填写一个');
        return;
    }
    _loading()
    // alert(JSON.stringify(view.listData))
    _upImg(headUrl, function(u){
        view.listData.head = u;
        // _ajax('api/reg/index', function (ret) {
        _ajax('register.php', function (ret) {
            _log(JSON.stringify(ret))
            _loadingClose();
            if (ret.code == '200') {
                _msg('提交成功')
                // setCookie('userid', ret.id);
                setCookie('userid', ret.ID);
                _hone();
            } else {
                _msg(ret.msg);
            }
        }, view.listData)
    })
}


// 修改
function getUserFilter(ziduan, value) {
    view.listData[ziduan] = value;
    closeModalFrm();
}

// 修改头像
var headUrl;

function changeHeader() {
    $('#head-file').click();
}
$('#head-file').on('change', function () {
    if(this.files[0]){
        headUrl = this.files[0];
        view.listData.head = window.URL.createObjectURL(this.files[0]);
        imgCss(view.listData.head, function (w, h) {
            if (w < h) {
                $('.tx').addClass('img-w').removeClass('img-h');
            }
        })
    }else{
        _msg('未选择文件')
    }
})

var cityLen = 1; // 1 当前城市 4常驻城市
function _changeCity(city) {
    if (cityLen == 1) {
        view.listData.city = city;
    } else {
        view.listData.offten_city = city;
    }
    closeModalFrm();
}
// 修改当前城市
function _showCity(len) {
    cityLen = len;
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'frame0/city');
}


// 多选
var ziduanType;

function openFilter(ziduan) {
    ziduanType = ziduan;
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'user/user_filter');
}


// 单选
var singleArr = [];

function openSingle(ziduan, type, title, arr) {
    ziduanType = ziduan;
    var btnArr = [];
    if (type == 1) { // 单选 规则
        for (var i = arr[0]; i < arr[1]; i++) {
            var obj = {
                "name": i
            };
            btnArr.push(obj);
        }
    } else { // 单选 不规则
        btnArr = _paramObj[ziduan];
    }
    singleArr = btnArr;
    $('#modal-wrap').removeClass('new-hide');
    _load('#modal-wrap', 'frame0/single');
}

// 隐藏模态框
function closeModalFrm() {
    $('#modal-wrap').addClass('new-hide');
}